package com.yhsimon.state;

//线程礼让 Yield 不一定成功，看cpu心情
public class TestThreadYield {
    public static void main(String[] args) {
        MyYield target=new MyYield();
        new Thread(target,"a").start();
        new Thread(target,"b").start();
    }
}
class MyYield implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始运行...");
        Thread.yield();//线程礼让
        System.out.println(Thread.currentThread().getName()+"线程已经停止...");
    }
}